<template>
  <div class="content">
    <el-row class="grid-content bg-purple-dark">
      <el-col :span="1">
        <span class="el-icon-search" style="margin-top: 15px;"></span>
      </el-col>
      <el-col :span="2" style="margin-top: 10px;">
        筛选查询
      </el-col>
      <el-col :span="12">
        创建时间
        <el-date-picker v-model="defectCondition.createStarttime" @change="changeStartTime" type="date" placeholder="开始日期"
          :picker-options="pickerOptions0">
        </el-date-picker>
        <el-date-picker v-model="defectCondition.createndtime" @change="changeEndTime" type="date" placeholder="结束日期"
          :picker-options="pickerOptions1">
        </el-date-picker>
      </el-col>
      <el-col :span="3" style="margin-top: 5px;margin-bottom: 5px;">
        <el-select v-model="defectCondition.projectId" clearable @clear="clearProjectId" placeholder="请选择项目" style="width: 120px;">
          <el-option v-for="project in projects" :key="project.projectId" :label="project.projectName"
            :value="project.projectId">
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="3" style="margin-top: 5px;margin-bottom: 5px;">
        <el-select v-model="defectCondition.defectStateId" clearable @clear="clearStateId" placeholder="请选择状态" style="width: 120px;">
          <el-option v-for="defectstate in defectstates" :key="defectstate.defectstateId"
            :label="defectstate.defectstateName" :value="defectstate.defectstateId">
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="1" style="margin-top: 5px;margin-bottom: 5px;">
        <el-button @click="getMyDefectCondition()" size="small">查询</el-button>
      </el-col>
      <el-col :span="1" style="margin-top: 5px;margin-bottom: 5px;">
        <el-button type="success" name="but-insert" id="but-insert" @click="insert()" size="small">新增</el-button>
      </el-col>
      <!-- <el-col :span="1" style="margin-top: 5px;margin-bottom: 5px;">
        <el-button type="danger" name="but-delete" id="but-delete" @click="del()" size="small">删除</el-button>
      </el-col> -->
    </el-row>

    <el-dialog title="添加" :visible.sync="dialogVisibleDefect" width="50%" hight="100%" :before-close="handleClose">
      <el-form :model="defect" :rules="defectRules" ref="defect" label-width="100px" class="demo-ruleForm">
        <el-form-item label="项目名称" prop="projectName" style="width: 400px;margin-left: 0px;">
          <el-input v-model="defect.projectName" @blur="isHasProject()" style="width: 200px;"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="dialogVisibleprojectform = true">搜索</el-button>
        </el-form-item>
        <el-form-item label="缺陷名称" prop="defectName" style="width: 200px">
          <el-input v-model="defect.defectName" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="缺陷描述" prop="defectDescription" style="width: 200px">
          <el-input v-model="defect.defectDescription" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="filesUrl" style="width: 200px">
          <el-upload class="upload-demo" action="http://localhost:8888/defect/uploadFile"
            :file-list="filelist" name="file" :with-credentials="true"
            :before-remove="beforeRemove" :on-success="respUrl" multiple :limit="2">
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="缺陷要求" prop="filesDescribe" style="width: 200px">
              <el-input v-model="defect.filesDescribe" style="width: 200px;"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="缺陷状态" prop="defectStateId" style="width: 262px;">
              <el-select v-model="defect.defectStateId" placeholder="请选择状态" style="width: 120px;">
                <el-option v-for="defectstate in defectNewStates" :key="defectstate.defectstateId"
                  :label="defectstate.defectstateName" :value="defectstate.defectstateId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="缺陷分类" prop="defectTypeId" style="width: 262px;">
                <el-select v-model="defect.defectTypeId" clearable placeholder="请选择缺陷分类" style="width: 150px;">
                  <el-option v-for="defectType in defectTypes" :key="defectType.defecttypeId"
                    :label="defectType.defecttypeName" :value="defectType.defecttypeId">
                  </el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="严重程度" prop="serverityId" style="width: 262px;">
                <el-select v-model="defect.serverityId" clearable placeholder="请选择严重程度" style="width: 150px;">
                  <el-option v-for="defectserverity in defectserveritys" :key="defectserverity.defectseverityId"
                    :label="defectserverity.defectseverityName" :value="defectserverity.defectseverityId">
                  </el-option>
                </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="优先级" prop="priorityId" style="width: 262px;">
              <el-select v-model="defect.priorityId" clearable placeholder="请选择优先级" style="width: 150px;">
                <el-option v-for="priority in prioritys" :key="priority.defectpriorityId"
                  :label="priority.defectpriorityName" :value="priority.defectpriorityId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预计工时" prop="fowardWorkHours" style="width: 262px;">
              <el-input v-model="defect.fowardWorkHours" @change="workhoursVild()" type="number" style="width: 150px;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划开始时间" prop="forwardStarttime">
              <el-date-picker v-model="defect.forwardStarttime" type="date" placeholder="选择开始日期" format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划完成时间" prop="forwardEndtime">
              <el-date-picker v-model="defect.forwardEndtime" type="datetime"
                placeholder="选择维修日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleDefect = false">取 消</el-button>
        <el-button type="primary" :disabled="disabledAdd" @click="adddefect('defect')">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 选择项目名称弹窗-->
    <el-dialog
      title="选择项目名称"
      :visible.sync="dialogVisibleprojectform"
      width="50%"
      hight="100%"
      :before-close="handleClose">
      <el-table
          :data="projectall"
          border
          style="width: 501px;">
          <el-table-column
            prop="projectId"
            label="项目编号"
            width="200"
          text-align: center>
          </el-table-column>
          <el-table-column
            prop="projectName"
            label="项目名字"
            width="200">
          </el-table-column>
          <el-table-column
                fixed="right"
                label="选择"
                width="100">
                <template slot-scope="scope">
                  <el-button @click="ischois(scope.row)" type="text" size="small">确认选择</el-button>
                </template>
          </el-table-column>
        </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisibleprojectform = false">取 消</el-button>
      </span>

      <el-pagination
        background
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :total="ProjectPage.total">
      </el-pagination>
    </el-dialog>


    <el-table
        :data="defectStatement"
        border
        style="width: 1181px;">
        <el-table-column
          prop="defectId"
          label="缺陷编号"
          width="120"
        text-align: center>
        </el-table-column>
        <el-table-column
          prop="defectName"
          label="缺陷名称"
          width="120">
        </el-table-column>
        <el-table-column
          prop="projectName"
          label="项目名称"
          width="120">
        </el-table-column>
        <el-table-column
          prop="priority"
          label="优先级"
          width="120">
        </el-table-column>
        <el-table-column
          prop="serverity"
          label="严重程度"
          width="120">
        </el-table-column>
        <el-table-column
          prop="defectType"
          label="缺陷分类"
          width="120">
        </el-table-column>
        <el-table-column
          prop="defectStateName"
          label="缺陷状态"
          width="120">
        </el-table-column>
        <el-table-column
          prop="defectChoiceName"
          label="指派给"
          width="120">
        </el-table-column>
        <el-table-column
          prop="forwardEndtime"
          label="计划完成时间"
          width="120">
        </el-table-column>
        <el-table-column
              fixed="right"
              label="操作"
              width="100">
              <template slot-scope="scope">
                <el-button @click="lookDefect(scope.row)" type="text" size="small" v-if="'新建'!=scope.row.defectstateSign">查看</el-button>
                <el-button @click="changeDefect(scope.row)" type="text" size="small" v-if="'新建'==scope.row.defectstateSign">修改</el-button>
                <el-button @click="removeDefect(scope.row)" type="text" size="small" v-if="'新建'==scope.row.defectstateSign">删除</el-button>
              </template>
        </el-table-column>
      </el-table>


      <el-dialog
        title="缺陷信息"
        :visible.sync="dialogVisibleDefectMessage"
        width="50%"
        hight="100%"
        :before-close="handleClose">
        <el-descriptions title="缺陷信息" border :column=2>
            <el-descriptions-item label="项目名称">{{defectStatementMessage.projectName}}</el-descriptions-item>
            <el-descriptions-item label="缺陷名称">{{defectStatementMessage.defectName}}</el-descriptions-item>
            <el-descriptions-item label="缺陷分类">{{defectStatementMessage.defectType}}</el-descriptions-item>
            <el-descriptions-item label="缺陷状态">{{defectStatementMessage.defectStateName}}</el-descriptions-item>
            <el-descriptions-item label="严重程度">{{defectStatementMessage.serverity}}</el-descriptions-item>
            <el-descriptions-item label="优先级">{{defectStatementMessage.priority}}</el-descriptions-item>
            <el-descriptions-item label="预计开始">{{defectStatementMessage.forwardStarttime}}</el-descriptions-item>
            <el-descriptions-item label="预计结束">{{defectStatementMessage.forwardEndtime}}</el-descriptions-item>
            <el-descriptions-item label="完成率">{{defectStatementMessage.defectCompletionRate}}</el-descriptions-item>
            <el-descriptions-item label="预计工时">{{defectStatementMessage.fowardWorkHours}}</el-descriptions-item>
            <el-descriptions-item label="缺陷描述" :span=24>{{defectStatementMessage.defectDescription}}</el-descriptions-item>
            <el-descriptions-item label="缺陷要求">{{defectStatementMessage.filesDescribe}}</el-descriptions-item>
        </el-descriptions>
        <div class="demo-image__preview">
          <el-image
            style="width: 300px; height: 200px" v-for="(item,index) in defectStatementMessage.imgs" :key="index"
            :src="item" >
          </el-image>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleDefectMessage = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisibleDefectMessage = false">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog
        title="修改缺陷"
        :visible.sync="dialogVisibleChangeDefect"
        width="50%"
        hight="100%"
        :before-close="handleClose">
        <el-descriptions title="缺陷信息" border :column=2>
            <el-descriptions-item label="项目名称">{{defectStatementMessage.projectName}}</el-descriptions-item>
            <el-descriptions-item label="缺陷名称">{{defectStatementMessage.defectName}}</el-descriptions-item>
            <el-descriptions-item label="缺陷状态">{{defectStatementMessage.defectStateName}}</el-descriptions-item>
            <el-descriptions-item label="完成率">{{defectStatementMessage.defectCompletionRate}}</el-descriptions-item>
        </el-descriptions>
        <el-form :model="defectStatementMessage" label-width="100px" class="demo-ruleForm">
          <el-row>
            <el-col :span="12">
              <el-form-item label="缺陷分类" prop="defecttypeName" style="width: 262px;">
                  <el-select v-model="defectStatementMessage.defectTypeId" placeholder="请选择缺陷分类" style="width: 150px;">
                    <el-option v-for="defectType in defectTypes" :key="defectType.defecttypeId"
                      :label="defectType.defecttypeName" :value="defectType.defecttypeId">
                    </el-option>
                  </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="严重程度" prop="defectseverityName" style="width: 262px;">
                  <el-select v-model="defectStatementMessage.serverityId" placeholder="请选择严重程度" style="width: 150px;">
                    <el-option v-for="defectserverity in defectserveritys" :key="defectserverity.defectseverityId"
                      :label="defectserverity.defectseverityName" :value="defectserverity.defectseverityId">
                    </el-option>
                  </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="优先级" prop="defectpriorityName" style="width: 262px;">
                <el-select v-model="defectStatementMessage.priorityId" placeholder="请选择优先级" style="width: 150px;">
                  <el-option v-for="priority in prioritys" :key="priority.defectpriorityId"
                    :label="priority.defectpriorityName" :value="priority.defectpriorityId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计工时" prop="fowardWorkHours" style="width: 262px;">
                <el-input v-model="defectStatementMessage.fowardWorkHours" type="number" style="width: 150px;"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="计划开始时间" prop="forwardStarttime">
                <el-date-picker v-model="defectStatementMessage.forwardStarttime" type="date" placeholder="选择开始日期" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划完成时间" prop="forwardEndtime">
                <el-date-picker v-model="defectStatementMessage.forwardEndtime" type="date"
                  placeholder="选择完成日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="缺陷描述" prop="defectDescription" style="width: 200px">
            <el-input v-model="defectStatementMessage.defectDescription" style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="缺陷要求" prop="filesDescribe" style="width: 200px">
            <el-input v-model="defectStatementMessage.filesDescribe" style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="图片" prop="img" style="width: 400px">
            <el-upload class="upload-demo" action="http://localhost:8888/defect/uploadFile"
              :file-list="filelist1" name="file" :with-credentials="true" list-type="picture"
              :before-remove="beforeRemove1" :on-success="respUrl1" multiple :limit="2">
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleChangeDefect = false">取 消</el-button>
          <el-button type="primary" @click="isChangeDefect">确 定</el-button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        pickerOptions0: {
          disabledDate: (time) => {
            if (this.defectCondition.createndtime != "" && this.defectCondition.createndtime != null) {
              return this.defectCondition.createndtime.getTime() < time.getTime();
            } else {
              return false;
            }
          }
        },
        pickerOptions1: {
          disabledDate: (time) => {
            if (this.defectCondition.createStarttime != '' && this.defectCondition.createStarttime !=
              null) {
              return time.getTime() < this.defectCondition.createStarttime.getTime();
            } else {
              return false;
            }

          }
        },
        defectCondition: {
          uid:null,
          defectCreatStarttime: null,
          defectCreatendtime: null,
          projectName: null,
          projectId: null,
          defectStateId: null,
          defectStateName: null,
          createStarttime:null,
          createndtime:null,
        },
        defect: {
          projectId: '',
          projectName: '',
          defectName: '',
          defectDescription: '',
          filesDescribe: '',
          defectTypeId: '',
          defectType: '',
          serverityId: '',
          serverity: '',
          priorityId: '',
          priority: '',
          fowardWorkHours: '',
          forwardStarttime: '',
          forwardEndtime: '',
          filesUrl:[],
          defectStateId:'',
          defectStateName:''
        },
        defectRules:{
          defectName:[
            { required: true, message: '请输入缺陷名称', trigger: 'blur' }
          ],
          defectDescription:[
            { required: true, message: '请输入缺陷描述', trigger: 'blur' }
          ],
          filesUrl: [
            { type: 'array', required: true, message: '请传至少一张图片', trigger: 'change' }
          ],
          filesDescribe: [
            { required: true, message: '请输入缺陷要求', trigger: 'blur' }
          ],
          defectTypeId:[
            { required: true, message: '请选择缺陷分类', trigger: 'change' }
          ],
          serverityId:[
            { required: true, message: '请选择缺陷严重程度', trigger: 'change' }
          ],
          priorityId:[
            { required: true, message: '请选择缺陷优先级', trigger: 'change' }
          ],
          defectStateId:[
            { required: true, message: '请选择新建状态', trigger: 'change' }
          ],
          fowardWorkHours:[
            { required: true, message: '请输入预计工时', trigger: 'blur' }
          ],
          forwardStarttime:[
            { required: true, message: '请选择预计开始时间', trigger: 'blur' }
          ],
          forwardEndtime:[
            { required: true, message: '请选择预计结束时间', trigger: 'blur' }
          ]
        },
        projects: [],
        defectstates: [],
        defectNewStates:[],
        defectTypes: [],
        defectserveritys: [],
        prioritys: [],
        dialogVisibleDefect: false,
        files: new FormData(),
        filelist:[],
        filelist1:[{url: ''},
        {url: ''}],
        projectall:[],
        ProjectPage:{
          pageNum:1,
          pageSize:4,
          total:2
        },
        dialogVisibleprojectform:false,
        defectStatement:[],
        defectStatementMessage:{},
        dialogVisibleDefectMessage:false,
        dialogVisibleChangeDefect:false,
        disabledAdd:true
      }
    },
    methods: {
      workhoursVild(){
        if(this.defect.fowardWorkHours<=0){
          this.$message({
            message: '预计工时不能小于等于0',
            type: 'warning'
          });
          this.defect.fowardWorkHours=1
        }
      },
      handleCurrentChange(val){
        this.ProjectPage.pageNum=val
        this.getAllProject()
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      beforeRemove(file, files) {
        var arr=new Array(0);
        for(var i=0;i<this.defect.filesUrl.length;i++){
          if(this.defect.filesUrl[i]!=file.url){
            arr=[this.defect.filesUrl[i]]
            this.defect.filesUrl=arr
            return
          }
        }
        this.defect.filesUrl=arr
        return this.$confirm(`确定移除 ${ file.name }？`);
      },
      beforeRemove1(file, files){
         var arr=new Array(0);
         console.log(arr.length)
        for(var i=0;i<this.defectStatementMessage.filesUrl.length;i++){
          if(this.defectStatementMessage.imgs[i]!=file.url){
           arr=[this.defectStatementMessage.imgs[i]]
            this.defectStatementMessage.imgs=arr
          return
          }
        }
        this.defectStatementMessage.imgs=arr

        return this.$confirm(`确定移除 ${ file.name }`);
      },
      getMyDefect() {
        var user=JSON.parse(sessionStorage.getItem("user"))
        console.log(user)
        this.defectCondition.uid=user.uid
        this.$axios.post("/defect/getMyDefect",this.defectCondition).then(resp=>{
          this.defectStatement=resp.data.data
          console.log(resp)
        })
      },
      clearProjectId(){
        this.defectCondition.projectId=null
      },
      clearStateId(){
        this.defectCondition.defectStateId=null
      },
      changeStartTime(){
        if(this.defectCondition.createStarttime==null){
          this.defectCondition.defectCreatStarttime=null
        }
      },
      changeEndTime(){
        if(this.defectCondition.createndtime==null){
          this.defectCondition.defectCreatendtime=null
        }
      },
      getMyDefectCondition(){
        var user=JSON.parse(sessionStorage.getItem("user"))
        this.defectCondition.uid=user.uid
        if(this.defectCondition.createStarttime!=null&&this.defectCondition.createndtime!=null){
          this.defectCondition.defectCreatStarttime=this.getDateFormat(this.defectCondition.createStarttime)
          this.defectCondition.defectCreatendtime=this.getDateFormat(this.defectCondition.createndtime)
          this.$axios.post("/defect/getMyDefect",this.defectCondition).then(resp=>{
            this.defectStatement=resp.data.data
            this.defectCondition.createStarttime=null
            this.defectCondition.createndtime=null
            this.defectCondition.defectCreatStarttime=null
            this.defectCondition.defectCreatendtime=null
            this.defectCondition.defectStateId=null
            this.defectCondition.projectId=null
          })
        }else if(this.defectCondition.createStarttime==null&&this.defectCondition.createndtime==null){
          console.log(this.defectCondition)
          this.$axios.post("/defect/getMyDefect",this.defectCondition).then(resp=>{
            if(resp.data.flag){
              this.defectStatement=resp.data.data
              this.defectCondition.createStarttime=null
              this.defectCondition.createndtime=null
              this.defectCondition.defectCreatStarttime=null
              this.defectCondition.defectCreatendtime=null
              this.defectCondition.defectStateId=null
              this.defectCondition.projectId=null

            }

          })
        }else{
          this.$message({
                    message: '请选择完整的时间范围',
                    type: 'warning'
                  });
        }

      },
      getDateFormat(mydate){
        var year=mydate.getYear()+1900
        var day=mydate.getDate()+""
        var month=mydate.getMonth()+1+""
        if(month.length==1){
          month="0"+month
        }
        if(day.length==1){
          day="0"+day
        }
        var time=""+year+"-"+month+"-"+day
        return time;
      },
      getDefectProjectName() {
        var user = JSON.parse(sessionStorage.getItem("user"))
        this.$axios.get("/defect/getDefectProjectName/" + user.uid).then(resp => {
          this.projects = resp.data.data
        })
      },
      getdefectState() {
        this.$axios.post("/defectstate/getdefectStateIsOk").then(resp => {
          this.defectstates = resp.data.data
        })
      },
      insert() {
        this.dialogVisibleDefect = true
      },
      getAllProject(){
        this.$axios.post("/project/getAllProjectByPage",this.ProjectPage).then(resp=>{
          this.projectall=resp.data.data.records

        })
      },
      ischois(defectProjectIdAndName){
        this.defect.projectId=defectProjectIdAndName.projectId
        this.defect.projectName=defectProjectIdAndName.projectName
        this.disabledAdd=false
        this.dialogVisibleprojectform=false
      },
      getdefectalldate(){
        /* 查询优先级，分类，严重程度,缺陷新建操作状态*/
        this.$axios.post("/defect/getDefectAllDate").then(resp=>{
          this.defectserveritys=resp.data.data.defectSeverityIdAndNameInfos
          this.defectTypes=resp.data.data.defectTypeIdAndNameInfos
          this.prioritys=resp.data.data.defectPriorityIdAndNameInfos
          this.defectNewStates=resp.data.data.defectstateNamesInfos
        })
        this.getAllProject()
      },
      respUrl(resp){
        this.defect.filesUrl.push(resp.data)
      },
      respUrl1(resp){
        this.defectStatementMessage.imgs.push(resp.data)
      },
      adddefect(defect){
        this.$refs[defect].validate((valid) => {
          if (valid) {
            for(var i=0;i<this.defectTypes.length;i++){
              if(this.defectTypes[i].defecttypeId==this.defect.defectTypeId){
                this.defect.defectType=this.defectTypes[i].defecttypeName
              }
            }

            for(var i=0;i<this.defectserveritys.length;i++){
              if(this.defectserveritys[i].defectseverityId==this.defect.serverityId){
                this.defect.serverity=this.defectserveritys[i].defectseverityName
              }
            }

            for(var i=0;i<this.prioritys.length;i++){
              if(this.prioritys[i].defectpriorityId==this.defect.priorityId){
                this.defect.priority=this.prioritys[i].defectpriorityName
              }
            }
            for(var i=0;i<this.defectNewStates.length;i++){
              if(this.defectNewStates[i].defectstateId==this.defect.defectStateId){
                this.defect.defectStateName=this.defectNewStates[i].defectstateName
              }
            }
            this.$axios.post("/defect/addDefect",this.defect).then(resp=>{
              if(resp.data.flag){
                this.dialogVisibleDefect=false
                this.getMyDefect()
                this.getDefectProjectName()
              }
            })
          } else {
               return false;
          }
      });

      },
      isHasProject(){
        var bool=true

        for(var i=0;i<this.projectall.length;i++){
          if(this.defect.projectName==this.projectall[i].projectName){
            bool=false
            this.defect.projectId=this.projectall[i].projectId
          }
        }
        if(bool){
          this.disabledAdd=true
          this.$message({
                    message: '没有该项目名称或项目名称为空',
                    type: 'warning'
                  });
        }else{
          this.disabledAdd=false
        }
      },
      changeDefect(defect){
        this.defectStatementMessage=defect
        for(var i=0;i<this.filelist1.length;i++){
          this.filelist1[i].url=defect.imgs[i]
        }
        this.dialogVisibleChangeDefect=true
      },
      lookDefect(defect){
        this.defectStatementMessage=defect
        this.dialogVisibleDefectMessage=true
      },
      removeDefect(defect){
        this.$axios.get("/defect/removeDefect/"+defect.defectId).then(resp=>{
          if(resp.data.flag){
            this.getMyDefect()
          }
        })
      },
      isChangeDefect(){
        for(var i=0;i<this.defectTypes.length;i++){
          if(this.defectTypes[i].defecttypeId==this.defectStatementMessage.defectTypeId){
            this.defectStatementMessage.defectType=this.defectTypes[i].defecttypeName
          }
        }
        for(var i=0;i<this.defectserveritys.length;i++){
          if(this.defectserveritys[i].defectseverityId==this.defectStatementMessage.serverityId){
            this.defectStatementMessage.serverity=this.defectserveritys[i].defectseverityName
          }
        }

        for(var i=0;i<this.prioritys.length;i++){
          if(this.prioritys[i].defectpriorityId==this.defectStatementMessage.priorityId){
            this.defectStatementMessage.priority=this.prioritys[i].defectpriorityName
          }
        }
        this.$axios.post("/defect/changeDefect",this.defectStatementMessage).then(resp=>{
          if(resp.data.flag){
            this.getMyDefect()
            this.dialogVisibleChangeDefect=false
          }
        })
      },
      // getCanDoStates(){
      //   var user = JSON.parse(sessionStorage.getItem("user"))
      //   this.$axios.get("/projectRoleUser/getCanDoStates/"+user.uid).then(resp=>{
      //     this.canDoStates=resp.data.data
      //   })
      // },
    },
    created() {
      this.getdefectState()
      this.getDefectProjectName()
      this.getdefectalldate()
      this.getMyDefect()
    }
  }
</script>

<style>
  .el-icon-search {

    left: -1060px;
  }

  .top_button {
    background-color: #F2F2F2;
    text-align: right;
  }
</style>
